package com.lagou.service.impl;

import com.lagou.annotation.QjcAutowired;
import com.lagou.annotation.QjcService;
import com.lagou.annotation.QjcTransactional;
import com.lagou.dao.AccountDao;
import com.lagou.pojo.Account;
import com.lagou.service.TransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@QjcService("transferService")
@QjcTransactional
public class TransferServiceImpl implements TransferService {
    @QjcAutowired
    private AccountDao accountDao;

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    @Override
    public void transfer(String fromCardNo, String toCardNo, Integer money) throws Exception {

        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);
        //设置转账金额
        from.setMoney(from.getMoney() - money);
        to.setMoney(to.getMoney() + money);
        // 更新金额
        accountDao.updateAccountByCardNo(from);
//        int a = 1 / 0;
        accountDao.updateAccountByCardNo(to);


    }
}
